﻿/*******************************************************************************
 * author : Kimm King 
 * datetime : 2008年8月19日16:40:54 
 * description : 一些常用操作
 */

//Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
Ext.Ajax.method = 'GET';

var $ = function(id) {
	return document.getElementById(id);
}

var extjsbase = {
	// LoginUser : "admin",
	// short cut for extjsbase.data
	getStore : function(p) {
		return extjsbase.data.getComboStore(p);
	},

	convert : function(sproperty, value) {
		return extjsbase.data.convert(sproperty, value);
	},

	getCmpByName : function(name) {
		var num = Ext.ComponentMgr.all.findIndex('name', name);
		if (num > -1) {
			return Ext.ComponentMgr.all.get(num);
			// } else {
		}
	},

	trimTime : function(value) {
		var t = String(value);
		if (t.indexOf(".") > -1) {
			return t.split(".")[0];
		}
	},

	createCommonCombo : function(name, label, value) {
		return {
			xtype : 'combo',
			fieldLabel : label,
			hiddenName : name,
			value : value || '',
			triggerAction : 'all',
			valueField : 'value',
			displayField : 'text',
			mode : 'local',
			store : extjsbase.getStore(name),
			readOnly : true
		};

	},

	createDiv : function(id, cls) {
		var sid = id || 'win';
		if (!$(sid)) {
			var div = document.createElement("div");
			div.className = cls || "x-hidden";
			div.id = sid;
			document.body.appendChild(div);
		};

	},
	getSystemFileTemp : function() {
		// debugger
		if (!this.tempfolder) {
			var fso;
			try {
				fso = new ActiveXObject("Scripting.FileSystemObject");
				this.tempfolder = fso.GetSpecialFolder(2);
			} catch (e) {
				Ext.MessageBox.alert("系统提示", e);
			}
			fso = null;
		}
		return this.tempfolder;
	},

	getKeys : function(obj) {

		if (obj) {
			var t = "";
			for (var o in obj) {
				t += o + ",";
			}
			return t;

		} else {
			return obj;
		}

	},
	
	/**
	checkFunctionCode : function(functionCode) // 检验用户权限code
	{
		return typeof(functionCode) == 'undefined' || functionCode == ''
				|| this.userFunctionCode.indexOf(functionCode) > -1;

	},
	checkToolBar : function(g) {
		var tbs = g.initialConfig.tbar;
		if (tbs) {
			Ext.each(tbs, function(t) {

				if (t.disabled === true || t.disabled === false) {
				} else if (t.functionCode) {
					t.disabled = !extjsbase.checkFunctionCode(t.functionCode);
				}

			})
		}
	},
	checkTreeBar : function(b) {
		var btns = b.items.items;
		if (btns) {
			Ext.each(btns, function(t) {
				if (t.functionCode) {
					t.disabled = !extjsbase.checkFunctionCode(t.functionCode);

				}
			})
		}
	},

	checkTreeNode : function(t) {
		// debugger
		var tree = t.root; // alert(tree.text + '--'+extjsbase.userFunctionCode);
		var childTree = tree.childNodes; // alert(childTree.length);
		var arr = new Array();
		if (childTree) {
			Ext.each(childTree, function(c) {
				var functionCode = c.attributes.functionCode;
				// alert(functionCode);
				if (functionCode) {
					if (extjsbase.userFunctionCode.indexOf(functionCode) < 0) {
						arr.push(c);
						// c.remove() ;
					}
				}
			})
		}
		for (var i = 0; i < arr.length; i++) {
			arr[i].remove();
		}
	},
	getUsercode : function() {
		var url = document.location;
		var params = url.search;
		var usercode = '';
		if (params.indexOf('usercode') > -1) {
			var posi = params.indexOf('usercode') + 'usercode'.length + 1;
			usercode = params.substring(posi, params.length);
		}
		return this.LoginUser = usercode;
	}
	,
	**/
	formatData:function(stext){	
		debugger
		var str=stext.el.dom.value; 
		var reg=/[\r\n\"]*/g; 
		var s=str.replace(reg,""); 
		stext.el.dom.value = s;
	},
	rnd:function(url){
		if(url.indexOf('?')>-1)
			return url+"&rnd="+Math.random();
		else{
			return url+"?rnd="+Math.random();
		}
	}
	
};
